package com.closer.service.biz.ai.core.saver;


import cn.hutool.core.util.StrUtil;
import com.closer.service.biz.ai.dto.HtmlCodeResult;
import com.closer.service.biz.ai.enums.CodeGenTypeEnum;
import com.closer.service.support.exception.BusinessException;
import com.closer.service.support.exception.ErrorCode;

/**
 * HTML代码保存模板
 */
public class HtmlCodeFileSaverTemplate extends CodeFileSaverTemplate<HtmlCodeResult> {

    @Override
    protected CodeGenTypeEnum getCodeGenType() {
        return CodeGenTypeEnum.HTML;
    }

    @Override
    protected void saveFiles(HtmlCodeResult result, String dirPath) {
        //保存HTML文件
        writeToFile(dirPath, "index.html", result.getHtmlCode());
    }

    @Override
    protected void validateInput(HtmlCodeResult result){
        super.validateInput(result);
        //HTML代码不能为空
        if(StrUtil.isBlank(result.getHtmlCode())){
            throw new BusinessException(ErrorCode.SYSTEM_ERROR, "HTML代码不能为空");
        }
    }

}
